//
//  LiveNoticeTableViewCell.m
//  YouinRTCDemo
//
//  Created by super on 2021/11/12.
//

#import "LiveNoticeTableViewCell.h"

@implementation LiveNoticeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self iniUI];
    }
    return self;
}

-(void)iniUI{
    
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    self.content = [UIView new];
    self.content.backgroundColor = [UIColor whiteColor];
    self.content.layer.cornerRadius = 3;
    self.content.layer.masksToBounds = YES;
    
    self.titleLabel = [UILabel new];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.textColor = rgba(102, 102, 102, 1);
    
    self.timeLabel = [UILabel new];
    self.timeLabel.numberOfLines = 0;
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    self.timeLabel.textColor = rgba(153, 153, 153, 1);
    
    self.sendButton = [[UIFactory shareInstace] setButton:UIButtonTypeCustom frame:CGRectZero image:nil title:@"发送" font:[UIFont systemFontOfSize:14] backColot:rgba(25, 148, 255, 1) textColor:[UIColor whiteColor] target:self action:nil layer:10];
    self.sendButton.userInteractionEnabled = false;
    
    
    [self.contentView addSubview:self.content];
    [self.content addSubview:self.titleLabel];
    [self.content addSubview:self.timeLabel];
    [self.content addSubview:self.sendButton];
    [self layoutIfNeeded];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(self.contentView).offset(15);
        make.right.mas_equalTo(self.contentView).offset(-15);
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.content).offset(9.5);
        make.left.mas_equalTo(self.content).offset(10.5);
        make.right.mas_equalTo(self.content).offset(-10.5);
    }];
    
    [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(15);
        make.left.mas_equalTo(self.content).offset(10.5);
        make.height.mas_equalTo(11.5);
        make.bottom.mas_equalTo(self.content).offset(-9.5);
    }];
    
    [self.sendButton mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.content).offset(-10);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(50);
        make.bottom.mas_equalTo(self.content).offset(-10);
    }];
    
}



-(void)setNoticeModel:(LiveNoticeModel *)noticeModel{
    self.titleLabel.text = noticeModel.content;
//    self.timeLabel.text = [NSString stringWithFormat:@"上次发送：%@",[self getLocalDateFormateUTCDate:noticeModel.createDate]];
    self.timeLabel.text = [NSString stringWithFormat:@"上次发送：%@",noticeModel.createDate];
}

-(NSString *)getLocalDateFormateUTCDate:(NSString *)utcDate
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //输入格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
    NSTimeZone *localTimeZone = [NSTimeZone localTimeZone];
    [dateFormatter setTimeZone:localTimeZone];
    
    NSDate *dateFormatted = [dateFormatter dateFromString:utcDate];
    //输出格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *dateString = [dateFormatter stringFromDate:dateFormatted];
    return dateString;
}

@end
